package com.hwadee.hello.service.impl;

import java.text.ParseException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hwadee.hello.entity.Student;
import com.hwadee.hello.mapper.StudentMapper;
import com.hwadee.hello.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentMapper studentMapper;
	
	@Override
	public int test(int arg) {
		System.out.println("----test------");
		return arg + 1;
	}

	@Override
	public int add(Student stu) throws ParseException {
		
		return studentMapper.insert(stu);
	}
	
	@Override
	@Transactional
	public int transfer(int a, int b, int age) {
		
		studentMapper.updatingAge(b, age);
		studentMapper.updatingAge(a, -age);
		
		return 1;
	}

	@Override
	public PageInfo<Student> getStudents(int p) {
		PageHelper.startPage(p, 5);
		List<Student> students = studentMapper.findAll();
		
		return new PageInfo<Student>(students);
	}

	@Override
	public int removeStudent(int id) {
		// TODO Auto-generated method stub
		return studentMapper.delete(id);
	}

	@Override
	public Student getStudentById(int id) {
		// TODO Auto-generated method stub
		return studentMapper.findById(id);
	}

}
